package com.ypd.shop.service.impl;

import java.sql.DriverAction;
import java.util.List;

import com.ypd.common.constant.AuctionConstants;
import com.ypd.common.core.domain.BaseEntity;
import com.ypd.common.utils.SecurityUtils;
import com.ypd.shop.domain.PostBox;
import com.ypd.shop.service.IPostBoxService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ypd.shop.mapper.ReportsMapper;
import com.ypd.shop.domain.Reports;
import com.ypd.shop.service.IReportsService;
import com.ypd.shop.service.IPropertiesService;
/**
 * 举报店铺Service业务层处理
 * 
 * @author lin
 * @date 2024-12-12
 */
@Service
public class ReportsServiceImpl implements IReportsService 
{
    @Autowired
    private ReportsMapper reportsMapper;
    @Autowired
    private IPostBoxService postBoxService;
    @Autowired
    private IPropertiesService propertiesSerivce;

    /**
     * 查询举报店铺
     * 
     * @param reportId 举报店铺主键
     * @return 举报店铺
     */
    @Override
    public Reports selectReportsByReportId(Long reportId)
    {
        return reportsMapper.selectReportsByReportId(reportId);
    }

    /**
     * 查询举报店铺列表
     * 
     * @param reports 举报店铺
     * @return 举报店铺
     */
    @Override
    public List<Reports> selectReportsList(Reports reports)
    {
        return reportsMapper.selectReportsList(reports);
    }

    /**
     * 新增举报店铺
     * 
     * @param reports 举报店铺
     * @return 结果
     */
    @Override
    public int insertReports(Reports reports)
    {
        //当进行举报的时候,需要有对应的举报人id和被举报人id才对
        reports.setReportUserId(SecurityUtils.getUserId());
        reports.setReportedId(propertiesSerivce.selectPropertiesByPropertyId(reports.getPropertyId()).getUserId());
        return reportsMapper.insertReports(reports);
    }

    /**
     * 修改举报店铺
     * 管理员端进行处理,同时发送邮件给被举报人和举报者
     * 
     * @param reports 举报店铺
     * @return 结果
     */
    @Override
    public int updateReports(Reports reports)
    {
        //进行处理操作之后,在后台修改处理状态
        reports.setStatus(1L);
        reports.setAdminId(SecurityUtils.getUserId());
        //发送邮件,也就是新增两封邮件,对象分别是举报人和被举报人(根据状态设置发送邮件的内容)
        PostBox postBox = new PostBox();
        postBox.setSenderId(AuctionConstants.ID_RUOYI);
        System.out.println(reports);
        postBox.setRecipientId(reports.getReportUserId());
        postBox.setContent(reports.getResponseAccuse());
        postBoxService.insertPostBox(postBox);
        //给被举报人进行回复
        postBox.setRecipientId(reports.getReportedId());
        postBox.setContent(reports.getResponseReported());
        postBoxService.insertPostBox(postBox);
        return reportsMapper.updateReports(reports);
    }



    /**
     * 批量删除举报店铺
     * 
     * @param reportIds 需要删除的举报店铺主键
     * @return 结果
     */
    @Override
    public int deleteReportsByReportIds(Long[] reportIds)
    {
        return reportsMapper.deleteReportsByReportIds(reportIds);
    }

    /**
     * 删除举报店铺信息
     * 
     * @param reportId 举报店铺主键
     * @return 结果
     */
    @Override
    public int deleteReportsByReportId(Long reportId)
    {
        return reportsMapper.deleteReportsByReportId(reportId);
    }
}
